<?php
/*
*************道达快递运单页面*******************
*/
class kd_orderApp extends MallbaseApp
{
    function index()//快递运单号查询
    {
		//横幅广告调用		
		$adver_list = $this->_get_flash_adver('77');
		$this->assign('adver_list', $adver_list[1]);
	
		$ydh = empty($_GET['ydh']) ? '' : htmldecode($_GET['ydh']);
		if($ydh)
		{
			$ydh = str_replace("\r","",$ydh);//textarea换行
			$ydh = str_replace("\n",",",$ydh);//textarea换行
			$ydh = str_replace("/",",",$ydh);//斜杠换行
			$ydh = str_replace("、",",",$ydh);//按钮的斜杠、换行
			$ydh = rtrim($ydh,",");
			$this->assign('get_ydh', $ydh);//赋值给百度查询
			$mod_kd_order =& m('kd_order');
			$yundan_list = $mod_kd_order->findAll(array(
				'fields'        => 'this.*',
				'conditions'    => db_create_in($ydh,'yundanhao','text'),
				'limit'         => '0,20', 
				'include'       =>  array(
				   'has_kdwuliu', //取出物流信息
				 ),	
			));	

			$this->assign('yundan_list', $yundan_list);
			//查询数量
			$count_yudan['substr_count'] = substr_count($ydh,',')+1;
			$count_yudan['count'] = count($yundan_list);
			$this->assign('count_yudan', $count_yudan);
		}

		$location = array( 0 => array( 'text' => '运单查询' ,'url' => 'yundan.html') );
		$this->_curlocal($location);
		$this->assign('location', $location);
		$this->_config_seo(array(
            'title' => '运单查询 - ' . Conf::get('site_name'),
        ));			
		$this->display('kd_order.yundanhao.html');
	}	
    function wpxz()//运单物品选择
    {
		//转运快件物品
		$kd_wupin_mod =& m('kd_wupin');
		$this->assign('kd_wupin', $kd_wupin_mod->get_options(0));
		
		$this->display('kd_order.wpxz.html');
	}	
	//调出频道的切换广告图片
	function _get_flash_adver($flash_id)
	{
		$this->adver_mod =& m('adver');
		$adver_list = $this->adver_mod->_get_adver_list($flash_id);
		$adver_list[$flash_id]['ad_img_name'] = unserialize($adver_list[$flash_id]['ad_img_name']);
		$adver_list[$flash_id]['ad_link'] = unserialize($adver_list[$flash_id]['ad_link']);
		$adver_list[$flash_id]['ad_img'] = unserialize($adver_list[$flash_id]['ad_img']);		
		$adver_list['flash']=array();$i=1;
		foreach($adver_list[$flash_id]['ad_img'] as $key => $var) 
		{
			$adver_list['flash'][$i]['ad_img_name'] = $adver_list[$flash_id]['ad_img_name'][$key];
			$adver_list['flash'][$i]['ad_link'] = $adver_list[$flash_id]['ad_link'][$key];
			$adver_list['flash'][$i]['ad_img'] = $var;
			$i++;
		}
		return $adver_list['flash'];
	}
	
	//合作客户查询页面
	function kehu()
	{
		//开始查询有效数据
		if(htmldecode($_GET['key'])){
			$conditions = " (lianxiren = '".htmldecode($_GET['key'])."' OR mobilphone = '".htmldecode($_GET['key'])."') AND";
		}		
		if(htmldecode($_GET['rukuhao'])){
			$conditions .= " (rukuhao1 <= ".htmldecode($_GET['rukuhao'])." AND rukuhao2 >= ".htmldecode($_GET['rukuhao']).") AND";
		}
		if(htmldecode($_GET['baoguan'])){
			$conditions .= " (baoguan1 <= '".htmldecode($_GET['baoguan'])."' AND baoguan2 >= '".htmldecode($_GET['baoguan'])."') AND";
		}		
		$conditions = rtrim($conditions,'AND');
		if($conditions)
		{
			$mod_kd_kehu =& m('kd_kehu');
			$kehu = $mod_kd_kehu->get($conditions);	
			$this->assign('kehu', $kehu);
		}
		//查询已经使用的入仓号和报关单号
		if($kehu)
		{
			$mod_kd_kehu_no =& m('kd_kehu_no');
			$kehu_no = $mod_kd_kehu_no->getAll("SELECT * FROM ".DB_PREFIX."kd_kehu_no WHERE zhudanNo >= '".$kehu['rukuhao1']."' AND zhudanNo <= '".$kehu['rukuhao2']."' GROUP BY zhudanNo DESC");			
			$this->assign('kehu_no', $kehu_no);	

			$kehu_no1 = $mod_kd_kehu_no->getAll("SELECT * FROM ".DB_PREFIX."kd_kehu_no WHERE baoguanNo >= '".$kehu['baoguan1']."' AND baoguanNo <= '".$kehu['baoguan2']."' GROUP BY baoguanNo DESC");		
			$this->assign('kehu_no1', $kehu_no1);				
		}

		//横幅广告调用====================================================================
		$adver_list = $this->_get_flash_adver('77');
		$this->assign('adver_list', $adver_list[1]);
        //缓存数据调用
		$cache_server =& cache_server();		
		$key = 'abouts_get_list';
        $category_about = $cache_server->get($key);
        if ($category_about === false){
			//调出所有公司内容列表
			$abouts_mod = &m('abouts');
			$category_about = $abouts_mod->find(array( 'order' => 'sort_order, cate_id' ));
			$cache_server->set($key, $category_about, 86400);
		}
		$category = array();
		foreach ($category_about as $key => $for_about){
			if ($for_about['parent_id']>0){
				$category[$for_about['parent_id']]['list'][] = $for_about;
			}else{
				$category[$key] = $for_about;
			}
		}
		$this->assign('category_about', $category);
		//左边导航结束=====================================================================	
		
		$location = array( 0 => array( 'text' => '合作客户查询' ,'url' => 'index.php?app=kd_order&act=kehu') );
		$this->_curlocal($location);
		$this->assign('location', $location);		
		$this->_config_seo(array(
            'title' => '合作客户查询 - ' . Conf::get('site_name'),
        ));		
		$this->display('kd_order.kehu.html');
	}
	//合作客户条码打印页面
	function kehu_print()
	{
		//开始查询有效数据
		if(htmldecode($_GET['key'])){
			$conditions = " (lianxiren = '".htmldecode($_GET['key'])."' OR mobilphone = '".htmldecode($_GET['key'])."' OR partner = '".htmldecode($_GET['key'])."') ";
		}
		if(intval($_GET['rukuhao'])>0){
			$conditions .= " AND (rukuhao1 <= ".intval($_GET['rukuhao'])." AND rukuhao2 >= ".intval($_GET['rukuhao']).") ";
		}			
		if($conditions)
		{
			$mod_kd_kehu =& m('kd_kehu');
			$kehu = $mod_kd_kehu->get($conditions);	
			$this->assign('kehu', $kehu);
		}
		
		//查看是否选中了某个入仓号来打印货号的
		if($kehu && htmldecode($_GET['rukuhao']))
		{
			$small = htmldecode($_GET['rukuhao_small']) ? htmldecode($_GET['rukuhao_small']) : '0001';
			$big = htmldecode($_GET['rukuhao_big']) ? htmldecode($_GET['rukuhao_big']) : '0101';
			if( !is_numeric($small) || strlen($small)<4 || strlen($small)>4 ){ $this->show_warning('最小货号必须为4位数字'); return; }
			if( !is_numeric($big) || strlen($big)<4  || strlen($big)>4 ){ $this->show_warning('最大货号必须为4位数字'); return; }
			if( $small >= $big  ){ $this->show_warning('最大货号 必须大于 最小货号'); return; }
			if( $small < 0001 || $big > 9999  ){ $this->show_warning('最小货号与最大货号的有效范围是：0001 - 9999'); return; }
			if( ($big-$small) > 200  ){ $this->show_warning('请注意，最小货号与最大货号之间不能超过200，一次最多只能打印200条记录'); return; }
			
			$rukuhao_small = htmldecode($_GET['rukuhao']) . $small;
			$rukuhao_big = htmldecode($_GET['rukuhao']) . $big;
			$rukuhao_print = array();
			for($i=$rukuhao_small;$i<=$rukuhao_big;$i++)
			{
				$rukuhao_print[] = array( 'rukuhao' => $i);
			}
			//print_r($rukuhao_print);
			$this->assign('search_list', array('rukuhao_small'=> $small,'rukuhao_big'=> $big,) );
			$this->assign('rukuhao_print', $rukuhao_print);
		
		}else{
			
			//显示入库号列表出来
			if($kehu['rukuhao1'] && $kehu['rukuhao2'])
			{
				$rukuhao = intval($kehu['rukuhao2']-$kehu['rukuhao1']);
				if($rukuhao>0)
				{
					$page = intval($kehu['page'])>0 ? intval($kehu['page']) : 1;
					$num_page = 10000;//显示页数				
					$page_num = ceil($rukuhao/$num_page);//可以分几页
					//根据当前页数获取要显示的号段
					if($rukuhao > $num_page){
						$rukuhao_big = $kehu['rukuhao1'] + $page * $num_page;
						$rukuhao_small = $rukuhao_big - $num_page;					
					}else{
						$rukuhao_big = $kehu['rukuhao2'];
						$rukuhao_small = $kehu['rukuhao1'];					
					}
	
					$rukuhao_list = array();
					for($i=$rukuhao_small;$i<=$rukuhao_big;$i++)
					{
						$rukuhao_list[] = array( 'rukuhao' => $i);
					}
					//print_r($rukuhao_list);
					$this->assign('rukuhao_list', $rukuhao_list);
				}
			}			
		}
				
		//横幅广告调用=====================================================================		
		$adver_list = $this->_get_flash_adver('77');
		$this->assign('adver_list', $adver_list[1]);
        //缓存数据调用
		$cache_server =& cache_server();		
		$key = 'abouts_get_list';
        $category_about = $cache_server->get($key);
        if ($category_about === false){
			//调出所有公司内容列表
			$abouts_mod = &m('abouts');
			$category_about = $abouts_mod->find(array( 'order' => 'sort_order, cate_id' ));
			$cache_server->set($key, $category_about, 86400);
		}
		$category = array();
		foreach ($category_about as $key => $for_about){
			if ($for_about['parent_id']>0){
				$category[$for_about['parent_id']]['list'][] = $for_about;
			}else{
				$category[$key] = $for_about;
			}
		}
		$this->assign('category_about', $category);
		//左边导航结束=====================================================================	

		$location = array( 0 => array( 'text' => '合作客户条形码打印' ,'url' => 'index.php?app=kd_order&act=kehu_print') );
		$this->_curlocal($location);
		$this->assign('location', $location);
			
		$this->_config_seo(array(
            'title' => '合作客户条形码打印 - ' . Conf::get('site_name'),
        ));	
	    $this->import_resource(array('script' => 'moonyes.js'));				
		$this->display('kd_order.kehu_print.html');		
	}
}
?>